安裝 Go
sudo apt-get install golang-go
wget https://dl.google.com/go/go1.12.13.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf go1.12.13.linux-amd64.tar.gz
sudo vim /etc/profile
加入這行到最後面
export PATH=$PATH:/usr/local/go/bin
go version
利用 apt(Ubuntu) 安裝 Helm
curl https://baltocdn.com/helm/signing.asc | sudo apt-key add -
sudo apt-get install apt-transport-https --yes
echo "deb https://baltocdn.com/helm/stable/debian/ all main" | sudo tee /etc/apt/sources.list.d/helm-stable-debian.list
sudo apt-get update
sudo apt-get install helm
git clone https://github.com/helm/helm.git
cd helm
make
建立 Jenkins 的 namespace
sudo kubectl create namespace jenkins
sudo kubectl get namespaces
helm repo add jenkinsci https://charts.jenkins.io
helm repo update
helm search repo jenkinsci
jenkins-volume.yaml
apiVersion: v1
kind: PersistentVolume
metadata:
name: jenkins-pv
namespace: jenkins-project
spec:
storageClassName: jenkins-pv
accessModes:
- ReadWriteOnce
capacity:
storage: 20Gi
persistentVolumeReclaimPolicy: Retain
hostPath:
path: /data/jenkins-volume/
sudo kubectl apply -f jenkins-volume.yaml
jenkins-sa.yaml
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: jenkins
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
annotations:
rbac.authorization.kubernetes.io/autoupdate: "true"
labels:
kubernetes.io/bootstrapping: rbac-defaults
name: jenkins
rules:
- apiGroups:
- '*'
resources:
- statefulsets
- services
- replicationcontrollers
- replicasets
- podtemplates
- podsecuritypolicies
- pods
- pods/log
- pods/exec
- podpreset
- poddisruptionbudget
- persistentvolumes
- persistentvolumeclaims
- jobs
- endpoints
- deployments
- deployments/scale
- daemonsets
- cronjobs
- configmaps
- namespaces
- events
- secrets
verbs:
- create
- get
- watch
- delete
- list
- patch
- apply
- update
- apiGroups:
- ""
resources:
- nodes
verbs:
- get
- list
- watch
- update
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
annotations:
rbac.authorization.kubernetes.io/autoupdate: "true"
labels:
kubernetes.io/bootstrapping: rbac-defaults
name: jenkins
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: jenkins
subjects:
- apiGroup: rbac.authorization.k8s.io
kind: Group
name: system:serviceaccounts:jenkins
sudo kubectl apply -f jenkins-sa.yaml
使用 yaml 檔安裝 Jenkins
jenkins-deployment.yaml
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: jenkins
spec:
replicas: 1
selector:
matchLabels:
app: jenkins
template:
metadata:
labels:
app: jenkins
spec:
containers:
- name: jenkins
image: jenkins/jenkins:lts
ports:
- containerPort: 8080
volumeMounts:
- name: jenkins-home
mountPath: /var/jenkins_home
volumes:
- name: jenkins-home
emptyDir: {}
sudo kubectl create -f jenkins-deployment.yaml -n jenkins
sudo kubectl get deployments -n jenkins
jenkins-service.yaml
apiVersion: v1
kind: Service
metadata:
name: jenkins
spec:
type: NodePort
ports:
- port: 8080
targetPort: 8080
selector:
app: jenkins
sudo kubectl create -f jenkins-service.yaml -n jenkins
sudo kubectl get services -n jenkins
查看 Jenkins Dashboard
密碼認證
sudo kubectl get pods -n jenkins
sudo kubectl logs <pod_name> -n jenkins
參考資料
https://dotblogs.com.tw/DizzyDizzy/2019/11/22/GoToInstall
https://helm.sh/docs/intro/install/
https://medium.com/@BuzonXXXX/ci-%E8%A8%AD%E5%AE%9Ajenkins%E9%80%A3%E7%B5%90github-private-repo-111c53d29047